package org.carabiner.example;

import java.awt.Dimension;
import java.awt.Point;
import java.awt.event.MouseEvent;

import javax.swing.JPanel;

import junit.framework.TestCase;

public class TestSquareMouseController extends TestCase
{
  public void testMouseController()
  {
    SquareMouseController controller = new SquareMouseController();    
    JPanel source = new JPanel();
    source.addMouseListener(controller);
    Point location = new Point(20, 30);
    MouseEvent e = new MouseEvent(source, MouseEvent.MOUSE_PRESSED, System.currentTimeMillis(), 0, location.x, location.y, 1, false);
    controller.mousePressed(e);
    assertEquals("Rect location was not set", location, controller.getRect().getLocation());
    
    Dimension size = new Dimension(40, 100);
    e = new MouseEvent(source, MouseEvent.MOUSE_RELEASED, System.currentTimeMillis(), 0, location.x + size.width, location.y + size.height, 1, false);
    controller.mouseReleased(e);
    assertEquals("Rect width/height was not set", size, controller.getRect().getSize());
    assertEquals(0, source.getMouseListeners().length);
  }
}
